﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using TrainingsApp.WebModel.Route;

namespace TrainingsApp.IPADApp {
    public class Global : System.Web.HttpApplication {

        void Application_Start(object sender, EventArgs e) {
            // Code that runs on application startup
            RouteManager.Register(RouteNames.Index, new RouteItem {
                Sort = 0,
                UserType = (int)(Model.UserType.Children | Model.UserType.SuperAdmin),
                Url = "/student/index.aspx"
            });

            RouteManager.Register(RouteNames.Index, new RouteItem {
                Sort = 1,
                UserType = (byte)Model.UserType.Teacher,
                Url = "/teacher/index.aspx"
            });

            RouteManager.Register(RouteNames.Preview_Index, new RouteItem {
                Sort = 1,
                UserType = (int)Model.UserType.Children,
                Url = "/Student/Previews.aspx"
            });
            RouteManager.Register(RouteNames.Preview_Ask, new RouteItem {
                Sort = 1,
                UserType = (int)Model.UserType.Children,
                Url = "/Student/Preview_Ask.aspx"
            });

            RouteManager.Register(RouteNames.Preview_Index, new RouteItem {
                Sort = 1,
                UserType = (int)Model.UserType.Teacher,
                Url = "/teacher/Previews.aspx"
            });

            RouteManager.Register(RouteNames.Preview_Group, new RouteItem {
                Sort = 1,
                UserType = (int)Model.UserType.Teacher,
                Url = "/teacher/preview_group.aspx"
            });

            RouteManager.Register(RouteNames.Preview_Quick, new RouteItem {
                Sort = 1,
                UserType = (int)Model.UserType.Teacher,
                Url = "/teacher/previewquickquery.aspx"
            });


            RouteManager.Register(RouteNames.User_Loging, new RouteItem {
                Sort = 1,
                UserType = (int)Model.UserType.Guest,
                Url = "/login.aspx"
            });

            RouteManager.Register(RouteNames.User_ForgetPassword, new RouteItem {
                Sort = 1,
                UserType = (int)(Model.UserType.Guest | Model.UserType.Children | Model.UserType.Teacher),
                Url = "/ForgetPassword.aspx"
            });


            RouteManager.Register(RouteNames.User_Register, new RouteItem {
                Sort = 1,
                UserType = (int)(Model.UserType.Guest | Model.UserType.Children | Model.UserType.Teacher | Model.UserType.SuperAdmin),
                Url = "/register.aspx"
            });

            RouteManager.Register(RouteNames.User_Error, new RouteItem {
                Sort = 1,
                UserType = (int)(Model.UserType.Guest | Model.UserType.Children | Model.UserType.Teacher | Model.UserType.SuperAdmin | Model.UserType.Admin),
                Url = "/error.aspx"
            });
            RouteManager.Register(RouteNames.Success, new RouteItem {
                Sort = 1,
                UserType = (int)(Model.UserType.Guest | Model.UserType.Children | Model.UserType.Teacher | Model.UserType.SuperAdmin | Model.UserType.Admin),
                Url = "/success.aspx"
            });

            RouteManager.Register(RouteNames.PreviewGuild, new RouteItem {
                Sort = 1,
                UserType = (int)(Model.UserType.Guest | Model.UserType.Children | Model.UserType.Teacher | Model.UserType.SuperAdmin | Model.UserType.Admin),
                Url = "/previewguild.aspx"
            });

            RouteManager.Register(RouteNames.AboutUs, new RouteItem {
                Sort = 1,
                UserType = (int)(Model.UserType.Guest | Model.UserType.Children | Model.UserType.Teacher | Model.UserType.SuperAdmin | Model.UserType.Admin),
                Url = "/AboutUs.aspx"
            });
        }

        void Application_End(object sender, EventArgs e) {
            //  Code that runs on application shutdown

        }

        void Application_Error(object sender, EventArgs e) {
            // Code that runs when an unhandled error occurs

        }

        void Session_Start(object sender, EventArgs e) {
            // Code that runs when a new session is started

        }

        void Session_End(object sender, EventArgs e) {
            // Code that runs when a session ends. 
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer 
            // or SQLServer, the event is not raised.

        }

    }
}
